package com.admin.business.background.venusOaOpinion;

import com.tiangong.framework.annotation.OpenApi;
import com.tiangong.framework.bo.CDO;
import com.tiangong.framework.bo.Return;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @description: 门户网意见建议表
 * @create: 2023-10-30 18:16:48
 **/
@Service("venusOaOpinionService")
@Slf4j
public class VenusOaOpinionService{

    @Resource
    VenusOaOpinionDao venusOaOpinionDao;

    /**
     * 添加门户网意见建议表,获取id数据
     *
     * @param cdoRequest - id:主键
     *                   - org_id:公司
     *                   - opinion_content:意见内容
     *                   - opinion_image:意见图片
     *                   - contact_name:联系人
     *                   - contact_phone:联系电话
     *                   - reply_user:回复人
     *                   - reply_content:回复内容
     *                   - update_time:修改时间
     *                   - begin_time:创建时间
     *                   - state:状态 0正常 1删除
     * @return
     * @author Ht
     * @create: 2023-10-30 18:16:48
     */
    @OpenApi
    public Return addVenusOaOpinion(CDO cdoRequest) {
        venusOaOpinionDao.addVenusOaOpinion(cdoRequest);
        CDO cdoResult = new CDO();
        if (cdoRequest.containsKey("id")) {
            cdoResult.set("id", cdoRequest.get("id"));
        }
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据id，更新门户网意见建议表数据
     *
     * @param cdoRequest - id:主键
     *                   - org_id:公司
     *                   - opinion_content:意见内容
     *                   - opinion_image:意见图片
     *                   - contact_name:联系人
     *                   - contact_phone:联系电话
     *                   - reply_user:回复人
     *                   - reply_content:回复内容
     *                   - update_time:修改时间
     *                   - begin_time:创建时间
     *                   - state:状态 0正常 1删除
     * @return
     * @author Ht
     * @create: 2023-10-30 18:16:48
     */
    @OpenApi
    public Return updateVenusOaOpinionById(CDO cdoRequest) {
        venusOaOpinionDao.updateVenusOaOpinionById(cdoRequest);
        return Return.SUCCESS;
    }

    /**
     * 根据id，删除门户网意见建议表数据
     *
     * @param cdoRequest - id:主键
     * @return
     * @author Ht
     * @create: 2023-10-30 18:16:48
     */
    @OpenApi
    public Return deleteVenusOaOpinionById(CDO cdoRequest){
        int count = venusOaOpinionDao.deleteVenusOaOpinionById(cdoRequest.getLong("id"));
        CDO cdoResult = new CDO();
        cdoResult.set("count", count);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据条件，删除门户网意见建议表数据
     *
     * @param cdoRequest
     * @return
     * @author Ht
     * @create: 2023-10-30 18:16:48
     */
    @OpenApi
    public Return deleteVenusOaOpinion(CDO cdoRequest) {
        int count = venusOaOpinionDao.deleteVenusOaOpinion(cdoRequest);
        CDO cdoResult = new CDO();
        cdoResult.set("count", count);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据ID，获取门户网意见建议表数据
     *
     * @param cdoRequest - id:主键
     * @return
     * @author Ht
     * @create: 2023-10-30 18:16:48
     */
    @OpenApi
    public Return getVenusOaOpinionById(CDO cdoRequest) {
        CDO cdoMapperResult = venusOaOpinionDao.getVenusOaOpinionById(cdoRequest.getLong("id"));
        return Return.valueOf(cdoMapperResult);
    }

    /**
     * 根据非空条件，获取门户网意见建议表数据列表
     *
     * @param cdoRequest
     * @return
     * @author Ht
     * @create: 2023-10-30 18:16:48
     */
    @OpenApi
    public Return getVenusOaOpinionListPage(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.getInteger("pageIndex")-1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusOaOpinionDao.getVenusOaOpinionListPage(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusOaOpinionDao.getVenusOaOpinionCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
    /**
     * 根据混合条件，获取门户网意见建议表数据列表
     *
     * @param cdoRequest - id:主键
     * @return
     * @author Ht
     * @create: 2023-10-30 18:16:48
     */
    @OpenApi
    public Return getVenusOaOpinionListPageByCondition(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.getInteger("pageIndex")-1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusOaOpinionDao.getVenusOaOpinionListPageByCondition(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusOaOpinionDao.getVenusOaOpinionCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
}
